package com.example.demo.operator;

import com.example.demo.annotation.OrderOperator;
import com.example.demo.enums.OrderStatusEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * @author zhy
 * @version 1.0.0
 * @ClassName CreateOrderOperator.java
 * @Description TODO
 * @createTime 2020年12月02日 14:51:00
 */
@Component
@OrderOperator
public class CreateOrderOperator extends AbstractOrderOperator {

    private Logger logger = LoggerFactory.getLogger(CreateOrderOperator.class);

    public CreateOrderOperator() {
        super.setStatus(OrderStatusEnum.CREATE_EVENT.status);
    }

    @Override
    public int handleEvent(int orderStatus, OrderStatusEnum orderStatusEnum) {
        if (orderStatus != OrderStatusEnum.CREATE_EVENT.status && orderStatus != OrderStatusEnum.ORDER_CANCEL.status) {
            throw new IllegalArgumentException(String.format("create operation can't handle the status: %s", orderStatus));
        }
        logger.info("进入创建订单状态扭转处理器");
        switch (orderStatusEnum) {
            case CREATE_EVENT:
                return OrderStatusEnum.NEED_PAY.status;
            case ORDER_CANCEL:
                return OrderStatusEnum.ORDER_CANCEL.status;
            default:
                return getStatus();
        }
    }
}
